package ufrj.safcp.demo.fingerprint;

import java.awt.Image;

import ufrj.safcp.tools.fingerprint.GriauleFingerprintHandler;
import ufrj.safcp.tools.fingerprint.IFingerprintHandler;
import ufrj.safcp.tools.fingerprint.IFingerprintReceiver;

public class ControleLeitor implements IFingerprintReceiver {
	
	protected IFingerprintHandler fh = GriauleFingerprintHandler.getInstance();
	
    private byte[] templateData1;
    private byte[] templateData2;

    private TelaInicial frm;

	public ControleLeitor(TelaInicial frm){
		
		this.frm = frm;
	   
		fh.init(25, this);
		fh.start();
		
    }
    
    public void destroy() {
    	fh.destroy();
    }
    
    
    public void receiveFingerprint(Image fingerprint, byte[] templateData, String template) {
    	
   		if(templateData1==null){
	    	 templateData1 = templateData;
	    	 
	    	 System.out.println("Template " + template);
	    	 
	    	 frm.showImage(fingerprint);
   		}else{
	       	 templateData2 = templateData;
	    	 
			System.out.println("Template " + template);
			
	    	 frm.showImage(fingerprint);
	    	 
	    	 boolean digitalValida = fh.match(templateData1, templateData2);
	    	 
	    	 frm.showSinal(digitalValida);
	    	 
	    	 templateData1 = null;
	    	 templateData2 = null;
	    	 
   			
   		}
    	
    }

	
    
    
}
